<?php
class InformationController extends Controller
{

    public function filters()
    {
        return array(
            //'accessControl', // perform access control for CRUD operations
            array('application.components.CLoginFilter'),
        );
    }

	/**
	 * Declares class-based actions.
	 */
	public function actions() {
		return array();
	}

    public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('list',),
                'users'=>array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('gethomeinfo','update'),
                'users'=>array('@'),
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }

	public function actionList($start=0,$type='news')
	{
		$query = array(
            'conditions'=>array('type'=>array('=='=>$type)),
		    'limit'=>_LIMITED_PAGE_SIZE,
		    'offset'=>(int)$start,
		    'select'=>array('_id','name','updatetime','thumb'),
            'sort'=>array('_id'=>EMongoCriteria::SORT_DESC),
		);
		$result = Information::model()->findAll($query);
		foreach ($result as $key => &$value) {
			$value['url'] = 'http://115.29.161.76/tao/info/'.(string)$value['_id'].'.html';
            unset($value['_id']);
            unset($value['subname']);
            unset($value['content']);
            unset($value['type']);
		}
		echoToMobile($result);
	}
}